package com.grammer.thread;

class Daemon implements Runnable {
    private Thread[] threads = new Thread[10];
    @Override
    public void run() {
        for (int i = 0; i < threads.length; i++) {
            threads[i] = new Thread(new DaemonSpawn());
            threads[i].start();
            System.out.print("DaemonSpawn " + i + " started , ");
        }

        for (int i = 0; i < threads.length; i++) {
            System.out.print("t[" + i + "].isDaemon()= " + threads[i].isDaemon() + ",");
        }

        while (true){
            Thread.yield();
        }
    }
}
class DaemonSpawn implements Runnable{
    @Override
    public void run() {
        while(true){
            Thread.yield();
        }
    }
}

public class Daemons {
    public static void main(String[] args) throws Exception{
        Thread d = new Thread(new Daemon());
        d.setDaemon(true);
        d.start();
        System.out.print("da.isDaemon()="+d.isDaemon()+" ,");
        Thread.sleep(1000);
    }
}
